﻿Imports System.IO

Public Class Frm_Rech_mowadafin

    Private Sub Frm_Rech_mowadafin_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Frm_mowadafin.Enabled = True
    End Sub

    Private Sub Frm_Rech_mowadafin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        comb_matorido_elbaht.SelectedIndex = 0
    End Sub

    Private Sub txt_rech_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_rech.TextChanged
        Try
            List_tous.Items.Clear()
            Partager.list_recherch.Clear()

            If comb_matorido_elbaht.SelectedItem = "الاسم العائلي" Then

                For Each av As Employe In Partager.moi.List_employe
                    If av.Nom_a.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.cin, av.Nom_a, av.Prenom_a}))

                    End If

                Next

            ElseIf comb_matorido_elbaht.SelectedItem = "الاسم الشخصي" Then

                For Each av As Employe In Partager.moi.List_employe
                    If av.Prenom_a.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.cin, av.Nom_a, av.Prenom_a}))
                    End If

                Next

            ElseIf comb_matorido_elbaht.SelectedItem = "رقم البطاقة الوطنية" Then

                For Each av As Employe In Partager.moi.List_employe
                    If av.cin.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.cin, av.Nom_a, av.Prenom_a}))
                    End If

                Next

            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        If txt_rech.Text = "" Then
            List_tous.Items.Clear()
        End If
    End Sub

    Private Sub Btn_choisi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_choisi.Click
        If List_tous.SelectedIndices.Count > 0 Then

            Dim j As Integer = 0
            Dim avo As Employe
            Try
              For Each i As Integer In List_tous.SelectedIndices
                    avo = Partager.list_recherch(i)
                    For Each khib As Employe In Partager.moi.List_employe
                        If avo.Id = khib.Id Then
                            Frm_mowadafin.List_tous.Items(j).Focused = True
                            Frm_mowadafin.List_tous.Items(j).Selected = True
                        End If
                        j += 1
                    Next

                Next
                Me.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        Else
            MsgBox("اختر موظف من القائمة", MsgBoxStyle.Information, "خطأ في البحث")
        End If
    End Sub

    Private Sub comb_matorido_elbaht_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles comb_matorido_elbaht.SelectedIndexChanged
        txt_rech.Clear()
    End Sub
End Class